package utils;

import Message.AccountSendMessageInfo;
import Message.Message;

import java.io.Serializable;
import java.util.LinkedList;


/**
 * 该类以链表形式存储每次服务器轮询返回给当前用户的来自同一用户发送给当前用户的所有聊天记录类AccountSendMessageInfo
 * */
public class AccountSendMessageInfoFromOneList implements Serializable {
    LinkedList<AccountSendMessageInfo> accountSendMessageInfoFromOneList;


    public int size() {
        return accountSendMessageInfoFromOneList.size();
    }

    public AccountSendMessageInfoFromOneList(){
        this.accountSendMessageInfoFromOneList = new LinkedList<AccountSendMessageInfo>();
    }

    public void add(AccountSendMessageInfo accountSendMessageInfo){
        accountSendMessageInfoFromOneList.add(accountSendMessageInfo);

    }

    public AccountSendMessageInfo get(int i){
        return  accountSendMessageInfoFromOneList.get(i);
    }

    public String toString(){
        StringBuilder messages= new StringBuilder();
        for (AccountSendMessageInfo accountSendMessageInfo : accountSendMessageInfoFromOneList)
            messages.append(accountSendMessageInfo.getTime()).append("\r\n").append(accountSendMessageInfo.getUserIdInDatabaseFrom()).append(" : ").append(accountSendMessageInfo.getMessageInfo()).append("\r\n").append("\r\n");

        return messages.toString();
    }
}
